package game.ghostleg;

import java.io.Serializable;

public class Interval implements Serializable {
	public static int MAX_ROW=80;
	private int isInserted[];
	public Interval() {
		isInserted	= new int[MAX_ROW];
		for ( int i = 0; i < MAX_ROW; i++ )
			isInserted[i]=0;
	}
	public boolean isValidRow ( int p_rowNum ) {
		if ( !(0 <= p_rowNum && p_rowNum < MAX_ROW ) )
		{
			System.out.println("Failed : Out of range");
			return false;
		}
		System.out.printf("Succeeded");
		return true;
	}
	public boolean insert ( int p_rowNum, int p_playerNum ) {
		System.out.printf("In Interval.Insert(%d,%d), ",p_rowNum,p_playerNum);
		
		if ( !isValidRow(p_rowNum) || isConnected(p_rowNum) )
			return false;
		return updateRow(p_rowNum,p_playerNum);
	}
	public boolean isConnected ( int p_rowNum ) {
		if ( 0 <= p_rowNum && p_rowNum < MAX_ROW )
			return isInserted[p_rowNum]!=0;
		return false;
	}
	private synchronized boolean updateRow ( int p_rowNum, int p_playerNum ) {
		if(isValidRow(p_rowNum))
		{
			isInserted[p_rowNum]=p_playerNum;
			return true;
		}
		return false;
	}
	/*
	public boolean updateInterval ( Interval p_interval ) {
		int i;
		for(i=0;i<MAX_ROW;i++)
			this.isInserted[i]=p_interval.isInserted[i];
		return true;
	}
	*/
}
